unit fe_main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  StdCtrls, FlEdit, ExtCtrls
  {$IFDEF conditionalexpressions}{$IF RTLVersion >= 15}, xpman{$IFEND}{$ENDIF};

type
  TForm1 = class(TForm)
    Label3: TLabel;
    FloatEdit3: TFloatEdit;
    SpinFloatEdit1: TSpinFloatEdit;
    Label4: TLabel;
    SpinFloatEdit2: TSpinFloatEdit;
    Label1: TLabel;
    FloatEdit1: TFloatEdit;
    Label2: TLabel;
    FloatEdit2: TFloatEdit;
    Panel1: TPanel;
    Label5: TLabel;
    CheckBox1: TCheckBox;
    cbAllowSep: TCheckBox;
    cbThousand: TCheckBox;
    procedure FloatEdit1Change(Sender: TObject);
    procedure FloatEdit2Change(Sender: TObject);
    procedure FloatEdit3Change(Sender: TObject);
    procedure SpinFloatEdit2Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpinFloatEdit1ComputedIncrement(Sender: TObject;
      const bIncrement: Boolean);
    procedure cbAllowSepClick(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure cbThousandClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FloatEdit1Change(Sender: TObject);
begin
  // change min val of spinfloatedit1
  with FloatEdit1 do
  begin
    SpinFloatEdit1.Min := Value;
    FloatEdit2.Min := Value;
  end;
end;

procedure TForm1.FloatEdit2Change(Sender: TObject);
begin
  // change max val of spinfloatedit1
  with FloatEdit2 do
  begin
    SpinFloatEdit1.Max := Value;
    FloatEdit1.Max := Value;
  end;
end;

procedure TForm1.FloatEdit3Change(Sender: TObject);
begin
  // change button increment of spinfloatedit1
  SpinFloatEdit1.Increment := FloatEdit3.Value;
end;

procedure TForm1.SpinFloatEdit2Change(Sender: TObject);
begin
  // change the decimal digits count, if the text is not ''
  if SpinFloatEdit2.Text <> ''
  then
    with SpinFloatEdit1 do
    begin
      Digits := Trunc(SpinFloatEdit2.Value);
      FloatEdit1.Digits := Digits;
      FloatEdit2.Digits := Digits;
      FloatEdit3.Digits := Digits;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label5.Caption := FloatEdit1.About;
end;


procedure TForm1.SpinFloatEdit1ComputedIncrement(Sender: TObject;
  const bIncrement: Boolean);
begin
  // on increment, set value = value *2
  // on decrement, set value = value / 2
  with TSpinFloatEdit(Sender)
  do
    if bIncrement
    then
      Value := Value +Value
    else
      Value := Value /2
end;

type
  TUnProtectedCustomFloatEdit = class(TCustomFloatEdit);

procedure TForm1.cbAllowSepClick(Sender: TObject);
var
  i: integer;
  cSep2: Char;
begin
  cSep2 := #0;
  if cbAllowSep.Checked then
    cSep2 := '!';
  for i := 0 to Pred(ComponentCount) do
    if Components[i] is TCustomFloatEdit then
      TUnProtectedCustomFloatEdit(Components[i]).AdditionalDecimalSeparator := cSep2;
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
const
  EnaColor : array[Boolean] of TColor = (clBtnFace, clWindow);
begin
  // for computed increment
  with FloatEdit3 do
  begin
    Enabled := not CheckBox1.Checked;
    Color := EnaColor[Enabled];
    if not Enabled
    then
      SpinFloatEdit1.OnComputedIncrement := SpinFloatEdit1ComputedIncrement
    else
      SpinFloatEdit1.OnComputedIncrement := nil;
  end;
end;

procedure TForm1.cbThousandClick(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to Pred(ComponentCount) do
    if Components[i] is TCustomFloatEdit then
      TUnProtectedCustomFloatEdit(Components[i]).SupportsThousandSeparator := cbThousand.Checked;
end;

end.
